package com.javaspeak.algorithm.fibonacci.conciserecursive;

import static org.junit.Assert.assertEquals;

import java.math.BigInteger;
import java.util.Iterator;

import org.junit.Test;
import org.junit.internal.TextListener;
import org.junit.runner.JUnitCore;


/**
 * @author John Dickerson
 */
public class FibonacciGeneratorTest {

    @Test
    public void testGetNumber(){

        for ( int i=0; i<100; i++ ){

            FibonacciGenerator.getNumber( i );
        }

        Iterator<BigInteger> fibonacciIterator =
            FibonacciGenerator.getCache().iterator();

        BigInteger start = fibonacciIterator.next();
        BigInteger middle = fibonacciIterator.next();
        BigInteger next;

        assertEquals( new BigInteger( "0" ), start );
        assertEquals( new BigInteger( "1" ), middle );

        System.out.println( start );
        System.out.println( middle );

        while ( fibonacciIterator.hasNext() ){

            next = fibonacciIterator.next();
            System.out.println( next );

            assertEquals( start.add( middle ), next );
            start = middle;
            middle = next;
        }
    }


    public static void main( String args[] ){

        JUnitCore junitCore = new JUnitCore();
        junitCore.addListener( new TextListener( System.out ) );
        junitCore.run( FibonacciGeneratorTest.class );
    }
}
